package com.milk.controller.admin;

import com.milk.entity.Carousels;
import com.milk.result.Result;
import com.milk.service.ICarouselsService;
import com.milk.vo.CarouselsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminCarouselsController")
@RequestMapping("/admin/carousels")
@CrossOrigin
public class CarouselsController {
    @Autowired
    private ICarouselsService carouselsService;

    /**
     * 查找所有轮播图照片
     * @return
     */
    @GetMapping
    public Result<CarouselsVO> selectAll(){
        CarouselsVO carouselsVO = carouselsService.selectAll();
        return Result.success(carouselsVO);
    }

    /**
     * 更新轮播图
     * @param carousels
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Carousels carousels){
        carouselsService.updateById(carousels);
        return Result.success();
    }

    /**
     * 新增轮播图
     * @param carousels
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Carousels carousels){
        carouselsService.save(carousels);
        return Result.success();
    }

    /**
     * 删除轮播图
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result deleteById(@PathVariable List<Long> ids){
        carouselsService.removeByIds(ids);
        return Result.success();
    }
}
